package demo1;

class Animal{
    protected String name;
    private int age;

    static {
        System.out.println("Animal的静态代码块");
    }

    {
        System.out.println("Animal得实例代码块");
    }

    //构造方法
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Animal带两个参数的构造方法");
    }

    public Animal(){
        System.out.println("Animal不带参数的构造方法");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat(){
        System.out.println(this.name + "正在吃饭");
    }

}

class Cat extends Animal{
    public String hair;

    static {
        System.out.println("Cat的静态代码块");
    }

    {
        System.out.println("Cat的实例代码块");
    }

    public Cat(){
        super();//从父类继承过来的东西， 得先构造父类的构造方法
        System.out.println("Cat的不带参数的构造方法");
    }

    public Cat(String name, int age, String hair) {
        super(name, age);
        this.hair = hair;
        System.out.println("Cat带三个参数的构造方法");
    }

    public static void testStatic(){
        // 不能在静态方法里面使用
        //System.out.println(this.hair);
    }
    public void mew(){
        System.out.println(this.name + "正在叫");
    }
}

public class Test {
    protected int k = 99;

    public static void main(String[] args) {
        Cat cat1 = new Cat("mimi", 8, "black");
        cat1.mew();
        cat1.eat();
    }

    public static void main1(String[] args) {
        Cat cat1 = new Cat("MM", 8, "black");
        System.out.println("=============");
        Cat cat2 = new Cat("mimi", 9, "black");
    }
}
